//
//  RmdStoryDetailCell.m
//  Travel assistant
//
//  Created by 杨帆 on 16/3/14.
//  Copyright © 2016年 旅游助手. All rights reserved.
//

#import "RmdStoryDetailCell.h"
static const CGFloat kVerMargin = 5;
static const CGFloat kHorMargin = 10;
@implementation RmdStoryDetailCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.photoView = [[UIImageView alloc]initWithFrame:(CGRectMake(kHorMargin, kVerMargin, 0.937*KScreenWidth, 0.33*KScreenHeight))];
        [self.contentView addSubview:self.photoView];
        
        self.textL = [[UILabel alloc]initWithFrame:(CGRectMake(0.031*KScreenWidth,0, 0.94*KScreenWidth, 0.2*KScreenHeight))];
        self.textL.font = [UIFont systemFontOfSize:12];
        self.textL.numberOfLines = 0;
        [self.contentView addSubview:self.textL];
    }
    return self;
}

- (CGFloat)setData:(RmdStoryDetailListItem *)item {
    
    self.item = item;
    
    CGFloat margin = 0;
    CGFloat cellHeight = margin;
    
    if (isEmptyString(item.photo)) {
        self.photoView.hidden = YES;
    } else {
        self.photoView.hidden = NO;
        [self.photoView sd_setImageWithURL:[NSURL URLWithString:item.photo] placeholderImage:nil];
        
        cellHeight = self.photoView.bottom;
        
    }
    
    if (isEmptyString(item.text)) {
        self.textL.hidden = YES;
    } else {
        
        cellHeight += kVerMargin;
        
        self.textL.hidden = NO;
        self.textL.text = item.text;
        CGSize size = [item.text sizeWithFontCompatible:self.textL.font constrainedToSize:CGSizeMake(self.textL.width, CGFLOAT_MAX)];
        self.textL.frame = CGRectMake(kHorMargin, cellHeight, self.textL.width, size.height);
        cellHeight += size.height;
        
    }
    cellHeight += margin;
    
    [self.contentView setHeight:cellHeight];
    [self setHeight:cellHeight];
    
    return cellHeight;
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
